<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/jquery-1.10.1.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .wrap {
            width: 400px;
            height: 400px;
            background-color: #6ff;
            overflow: hidden;
            margin: 100px;
            position: relative;
        }

        .sub {
            width: 300px;
            height: 300px;
            background-color: #f00;
            overflow: hidden;
            margin: 50px;

        }

        .txt {
            width: 100px;
            height: 100px;
            background-color: blue;
            overflow: hidden;
            margin: 100px;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <div class="sub">
            <div class="txt"></div>
        </div>
    </div>
</body>
<script>
    var txt = document.querySelector(".txt");

    // 原生
    // offsetLeft, offsetTop  (偏移  margin position)  
    // offsetLeft, offsetTop  相对于参照物父元素的偏移
    // 自当前元素的父元素开始找到各种定位属性(relative,absoute,fixed),如果能找到 该元素就是参照物父元素,找不到 继续向上一层查找,以此类推 ,直到body为止

    console.log(txt.offsetParent, txt.offsetLeft, txt.offsetTop);

    // console.log($(".txt").offsetParent())
    console.log($(".txt").prop("offsetParent"), $(".txt").prop("offsetLeft"), $(".txt").prop("offsetTop"))

</script>

</html>